from .models import OperationLog
from utils.viewset import CustomModelViewSet
from .serializers import OperationLogSerializer
from .filter import OperationLogFilter
from rest_framework.decorators import action
from utils.json_response import SuccessResponse


class OperationLogViewSet(CustomModelViewSet):
    """
    操作日志接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = OperationLog.objects.order_by('-create_datetime')
    serializer_class = OperationLogSerializer
    filter_class = OperationLogFilter

    @action(methods=['delete'], detail=False)
    def multiple_delete(self, request, *args, **kwargs):
        self.get_queryset().delete()
        return SuccessResponse(data=[], message="删除成功")
